package com.obtk.byproperty.controller;

import com.obtk.byproperty.pojo.JsonResult;
import com.obtk.byproperty.pojo.Repair;
import com.obtk.byproperty.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/repair")
public class RepairController {
    @Autowired
    private RepairService repairService;

    @RequestMapping("/getRepair")
    public List<Repair> getRepair(String ownerName,String status){
        System.out.println(ownerName);
       List<Repair> repairList= repairService.selectByName(ownerName,status);
           return repairList;
    }
    @RequestMapping("/selectDeviceName")
    public List<Repair> selectDeviceName(String ownerName,String deviceName){
        List<Repair> repairList = repairService.selectDeviceName(ownerName,deviceName);
        return repairList;
    }
    @RequestMapping("/getBuildingName")
    public List<String> getBuildingName(){
       List<String> buuildingNames= repairService.getBuildingName();
       return buuildingNames;
    }
    @RequestMapping("/addRepair")
    public JsonResult addRepair(Repair repair){
       Boolean add= repairService.addRepair(repair);
        if(add){
            return JsonResult.success(repair).put("code",1).put("msg","填写保修成功");
        }
        return JsonResult.fail(null).put("code",0).put("msg","填写保修失败");
    }
    @RequestMapping("/deleteRepairId")
    public JsonResult deleteRepairId(Integer repairId){
        Boolean delete=repairService.deleteRepairId(repairId);
        if(delete){
            return JsonResult.success(repairId).put("code",1).put("msg","删除报修单成功");
        }
        return JsonResult.fail(null).put("code",0).put("msg","删除报修单失败");
    }
    @RequestMapping("/getRepairById")
    public Repair getRepairById(Integer repairId){
        Repair repair= repairService.selectById(repairId);
        System.out.println(repair.getRepairImage());
       return repair;
    }
}
